import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  // 登录页面
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   children: [{
  //     path: 'dashboard',
  //     name: 'Dashboard',
  //     component: () => import('@/views/dashboard/index'),
  //     meta: { title: '首页', icon: 'dashboard' }
  //   }]
  // },
  
  // 首页页面
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-house' }
    }]
  },

  // 无用部分--------------------------------------------------------------------------------------------------------
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '销售管理', icon: 'el-icon-sell' },
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '采购管理', icon: 'el-icon-shopping-cart-1' },
  },
  // 截至线------------------------------------------------------------------------------------------------------------
  // 库存管理===========================================================
  {
    path: '/kucun',
    component: Layout,
    redirect: '/kucun',
    name: 'kucun',
    meta: {
      title: '库存管理',
      icon: 'el-icon-coin'
    },
    children: [
      {
        path: 'rukuguanli',
        component: () => import('@/views/kucun/rukuguanli'), // Parent router-view
        name: 'rukuguanli',
        meta: { title: '入库管理' },
        children: [
          {
            path: 'caigouruku',
            component: () => import('@/views/kucun/rukuguanli/caigouruku.vue'),
            name: 'caigouruku',
            meta: { title: '采购入库' }
          },
          {
            path: 'caigoutuihuo',
            component: () => import('@/views/kucun/rukuguanli/caigoutuihuo.vue'),
            name: 'caigoutuihuo',
            meta: { title: '采购退货出库(红入)' }
          },
          {
            path: 'panying',
            component: () => import('@/views/kucun/rukuguanli/panying.vue'),
            name: 'panying',
            meta: { title: '盘盈入库' }
          },
          {
            path: 'zhangdun',
            component: () => import('@/views/kucun/rukuguanli/zhangdun.vue'),
            name: 'zhangdun',
            meta: { title: '涨吨入库' }
          },
          {
            path: 'qitaruku',
            component: () => import('@/views/kucun/rukuguanli/qitaruku.vue'),
            name: 'qitaruku',
            meta: { title: '其他入库' }
          },
        ]
      },
      //出库管理===========================================================
      {
        path: 'chukuguanli',
        component: () => import('@/views/kucun/chukuguanli'), // Parent router-view
        name: 'chukuguanli',
        meta: { title: '出库管理' },
        children: [
          {
            path: 'xiaoshouchuku',
            component: () => import('@/views/kucun/chukuguanli/xiaoshouchuku.vue'),
            name: 'xiaoshouchuku',
            meta: { title: '销售出库' }
          },
          {
            path: 'xiaoshoutuihuo',
            component: () => import('@/views/kucun/chukuguanli/xiaoshoutuihuo.vue'),
            name: 'xiaoshoutuihuo',
            meta: { title: '销售退货入库(红出)' }
          },
          {
            path: 'pankuichuku',
            component: () => import('@/views/kucun/chukuguanli/pankuichuku.vue'),
            name: 'pankuichuku',
            meta: { title: '盘亏出库' }
          },
          {
            path: 'qitachuku',
            component: () => import('@/views/kucun/chukuguanli/qitachuku.vue'),
            name: 'qitachuku',
            meta: { title: '其他出库' }
          },
        ]
      },
      //其他管理===========================================================
      {
        path: 'qitaguanli',
        component: () => import('@/views/kucun/qitaguanli'), // Parent router-view
        name: 'qitaguanli',
        meta: { title: '其他管理' },
        children: [
          {
            path: 'kucundiaobo',
            component: () => import('@/views/kucun/qitaguanli/kucundiaobo.vue'),
            name: 'kucundiaobo',
            meta: { title: '库存调拨' }
          },
          {
            path: 'chengbentiaozheng',
            component: () => import('@/views/kucun/qitaguanli/chengbentiaozheng.vue'),
            name: 'chengbentiaozheng',
            meta: { title: '成本调整' }
          },
          {
            path: 'kucunpandian',
            component: () => import('@/views/kucun/qitaguanli/kucunpandian.vue'),
            name: 'kucunpandian',
            meta: { title: '库存盘点' }
          },
        ]
      },
      //即时库存===========================================================
      {
        path: 'jishikucun',
        component: () => import('@/views/kucun/jishikucun'), // Parent router-view
        name: 'jishikucun',
        meta: { title: '即时库存' },
        children: [
          {
            path: 'wuliaokucun',
            component: () => import('@/views/kucun/jishikucun/wuliaokucun.vue'),
            name: 'wuliaokucun',
            meta: { title: '物料库存' }
          },
          {
            path: 'wuliaopicikucun',
            component: () => import('@/views/kucun/jishikucun/wuliaopicikucun.vue'),
            name: 'wuliaopicikucun',
            meta: { title: '物料批次库存' }
          },
          {
            path: 'cangkuwuliaokucun',
            component: () => import('@/views/kucun/jishikucun/cangkuwuliaokucun.vue'),
            name: 'cangkuwuliaokucun',
            meta: { title: '仓库物料库存' }
          },
          {
            path: 'xiangxikucun',
            component: () => import('@/views/kucun/jishikucun/xiangxikucun.vue'),
            name: 'xiangxikucun',
            meta: { title: '详细库存' }
          },
        ]
      },
      //出入库统计===========================================================
      {
        path: 'churukutongji',
        component: () => import('@/views/kucun/churukutongji'), // Parent router-view
        name: 'churukutongji',
        meta: { title: '出入库统计' },
        children: [
          {
            path: 'churukuyuehuizong',
            component: () => import('@/views/kucun/churukutongji/churukuyuehuizong.vue'),
            name: 'churukuyuehuizong',
            meta: { title: '出入库月汇总' }
          },
          {
            path: 'churukurihuizong',
            component: () => import('@/views/kucun/churukutongji/churukurihuizong.vue'),
            name: 'churukurihuizong',
            meta: { title: '出入库日汇总' }
          },
          {
            path: 'churukumingxi',
            component: () => import('@/views/kucun/churukutongji/churukumingxi.vue'),
            name: 'churukumingxi',
            meta: { title: '出入库明细' }
          },
        ]
      },
    ]
  },
  // 无用部分--------------------------------------------------------------------------------------------------------
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '应收与收款', icon: 'el-icon-wallet' },
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '应收与付款', icon: 'el-icon-bank-card' },
  },
  // 截至线------------------------------------------------------------------------------------------------------------
  
  //发票登记===========================================================
  {
    path: '/fapiaodengji',
    // component: () => import('@/views/fapiaodengji'), // Parent router-view
    component: Layout,
    redirect: '/fapiaodengji',
    name: 'fapiaodengji',
    meta: {
      title: '发票登记',
      icon: 'el-icon-tickets'
    },
    children: [
          {
            path: 'xiaoshoufapiao',
            component: () => import('@/views/fapiaodengji/xiaoshoufapiao.vue'),
            name: 'xiaoshoufapiao',
            meta: { title: '销售发票' }
          },
          {
            path: 'xiaoshoufapiaohongchong',
            component: () => import('@/views/fapiaodengji/xiaoshoufapiaohongchong.vue'),
            name: 'xiaoshoufapiaohongchong',
            meta: { title: '销售发票(红冲)' }
          },
          {
            path: 'xiaoshoufapiaotuihuo',
            component: () => import('@/views/fapiaodengji/xiaoshoufapiaotuihuo.vue'),
            name: 'xiaoshoufapiaotuihuo',
            meta: { title: '销售发票(退货)' }
          },
          {
            path: 'caigoufapiao',
            component: () => import('@/views/fapiaodengji/caigoufapiao.vue'),
            name: 'caigoufapiao',
            meta: { title: '采购发票' }
          },
          {
            path: 'caigoufapiaohongchong',
            component: () => import('@/views/fapiaodengji/caigoufapiaohongchong.vue'),
            name: 'caigoufapiaohongchong',
            meta: { title: '采购发票(红冲)' }
          },
          {
            path: 'caigoufapiaotuihuo',
            component: () => import('@/views/fapiaodengji/caigoufapiaotuihuo.vue'),
            name: 'caigoufapiaotuihuo',
            meta: { title: '采购发票(退货)' }
          },
    ]
  },
  //基础资料===========================================================
  {
    path: '/jichuziliao',
    // component: () => import('@/views/jichuziliao'), // Parent router-view
    component: Layout,
    redirect: '/jichuziliao',
    name: 'jichuziliao',
    meta: {
      title: '基础资料',
      icon: 'el-icon-receiving'
    },
    children: [
          {
            path: 'kehu',
            component: () => import('@/views/jichuziliao/kehu.vue'),
            name: 'kehu',
            meta: { title: '客户' }
          },
          {
            path: 'gongyingshang',
            component: () => import('@/views/jichuziliao/gongyingshang.vue'),
            name: 'gongyingshang',
            meta: { title: '供应商' }
          },
          {
            path: 'cangku',
            component: () => import('@/views/jichuziliao/cangku.vue'),
            name: 'cangku',
            meta: { title: '仓库' }
          },
          {
            path: 'wuliaofenlei',
            component: () => import('@/views/jichuziliao/wuliaofenlei.vue'),
            name: 'wuliaofenlei',
            meta: { title: '物料分类' }
          },
          {
            path: 'wuliao',
            component: () => import('@/views/jichuziliao/wuliao.vue'),
            name: 'wuliao',
            meta: { title: '物料' }
          },
          {
            path: 'jiliangdanwei',
            component: () => import('@/views/jichuziliao/jiliangdanwei.vue'),
            name: 'jiliangdanwei',
            meta: { title: '计量单位' }
          },
          {
            path: 'bizhong',
            component: () => import('@/views/jichuziliao/bizhong.vue'),
            name: 'bizhong',
            meta: { title: '币种' }
          },
          {
            path: 'yinhangzhanghu',
            component: () => import('@/views/jichuziliao/yinhangzhanghu.vue'),
            name: 'yinhangzhanghu',
            meta: { title: '银行账户' }
          },
    ]
  },
  // 无用部分--------------------------------------------------------------------------------------------------------
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '业务监控', icon: 'el-icon-video-camera' },
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '系统监控', icon: 'el-icon-set-up' },
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '系统管理', icon: 'el-icon-setting' },
  },
  // 截至线------------------------------------------------------------------------------------------------------------
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
